from enum import Enum


class Stock(Enum):
    # '2020-01-13,6.70,6.93,6.93,6.67,54385,37161012.00,3.86'
    code = 'code'
    name = 'name'
    exchange = 'exchange'
    rq = 'rq'  # 日期
    kp = 'kp'  # 开盘
    sp = 'sp'  # 收盘
    max = 'max'  # 最高值
    min = 'min'  # 最低值
    cjl = 'cjl'  # 成交量
    cje = 'cje'  # 成交额
    zf = 'zf'  # 振幅
    zhf = 'zhf'  # 涨幅

    # self:k线
    def format_k_line(self):
        kline_arr = self.split(',')
        kp = float(kline_arr[1])
        sp = float(kline_arr[2])
        zhf = ''
        if kp > sp:
            zhf = (kp - sp) / kp
        else:
            zhf = (sp - kp) / sp
        # print(zhf)
        day_k_info = {Stock.rq.value: kline_arr[0], Stock.kp.value: kline_arr[1], Stock.sp.value: kline_arr[2],
                      Stock.max.value: kline_arr[3], Stock.min.value: kline_arr[4], Stock.cjl.value: kline_arr[5],
                      Stock.cje.value: kline_arr[6], Stock.zf.value: kline_arr[7], Stock.zhf.value: zhf}
        return day_k_info
